package com.cloudeasy.user.aop;

import com.cloudeasy.user.service.UserRoleService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

/**
 * 用户角色的切面类，处理解冻
 */
@Aspect
@Component
public class UserRoleAspect {
    private final UserRoleService userRoleService;

    public UserRoleAspect(@Lazy UserRoleService userRoleService) {
        this.userRoleService = userRoleService;
    }

    @Pointcut("execution(public * com.cloudeasy.user.service.UserRoleService.*(..))" +
            "&&!execution(public * com.cloudeasy.user.service.UserRoleService.unlocked(..))")
    public void point() {
    }

    @Before("point()")
    public void before(JoinPoint joinPoint) {
        userRoleService.unlocked();
    }
}
